package com.zlx.sharelive.activity;

import android.view.View;
import android.widget.TextView;

import com.zlx.module_base.base_ac.BaseAc;
import com.zlx.module_base.base_api.res_data.MsgBean2;
import com.zlx.module_base.base_api.util.ApiUtil;
import com.zlx.module_base.base_util.SPUtil;
import com.zlx.module_network.api1.livedata.BaseObserver;
import com.zlx.module_network.api1.livedata.BaseObserverCallBack;
import com.zlx.module_network.bean.ApiResponse;
import com.zlx.sharelive.R;

import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

public class MessageDetailsAc extends BaseAc {

    @BindView(R.id.tv_title)
    TextView tv_title;
    @BindView(R.id.tv_time)
    TextView tv_time;
    @BindView(R.id.tv_text)
    TextView tv_text;

    private String id;

    @Override
    protected int getLayoutId() {
        return R.layout.ac_message_details;
    }

    @Override
    public void initViews() {
        super.initViews();

        id = getIntent().getStringExtra("id");
        initRecyclerView();
        getMsg();
    }

    private void initRecyclerView() {

    }

    private void getMsg() {
        ApiUtil.getUserApi().getMsg2(SPUtil.getToken(this),
                id).observe(this, new BaseObserver<>(new BaseObserverCallBack<ApiResponse<MsgBean2>>() {
            @Override
            public void onSuccess(ApiResponse<MsgBean2> data) {
                if (null != data) {
                    if (null != data.getData()) {
                        if (data.getData().getCode() == 0) {
                            if (null != data.getData().getInfo()) {
                                setDataInfo(data.getData().getInfo());
                            }
                        }
                    }
                }
            }
        }));
    }

    @OnClick({R.id.iv_back})
    public void setOnClick(View view) {
        switch (view.getId()) {
            case R.id.iv_back:
                finish();
                break;
        }
    }

    private void setDataInfo(List<MsgBean2.InfoDTO> info) {
        tv_title.setText(info.get(0).getMsgTitle());
        tv_text.setText(info.get(0).getMsgDetails());
        tv_time.setText(info.get(0).getCreateTime());
    }
}
